$(document).ready(function() {

	if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
	   is_mobile = true;
	}

	$('.mobile-nav-head').on('click', function() {
		if ($('.mobile-nav-head span').hasClass('glyphicon-plus')) {
			console.log("down");
			$('.nav-bar').slideDown('slow', function() {
				$('.mobile-nav-head span').removeClass('glyphicon-plus').addClass('glyphicon-minus');
			});
		} else {
			console.log("up");
			$('.nav-bar').slideUp('slow', function() {
				$('.mobile-nav-head span').removeClass('glyphicon-minus').addClass('glyphicon-plus');
			});
		}
	});

	$('.nav-bar > li > a').on('click', function() {
		var that = $(this);
		var sub_menu = $(this).parent('li').find('.sub-menu');
		console.log(sub_menu);
		if (sub_menu.length > 0) {
			console.log('yes');
			
			if (that.find('span').hasClass('glyphicon-plus')) {
				sub_menu.slideDown('slow', function() {
					that.find('span').removeClass('glyphicon-plus').addClass('glyphicon-minus');
				});
			} else {
				sub_menu.slideUp('slow', function() {
					that.find('span').removeClass('glyphicon-minus').addClass('glyphicon-plus');
				});
			}

			
			return false;
		} else {
			console.log('no');

			return true;
		}
	});

	$("#cmbArea").change(function(){
		var cmbArea = $('#cmbArea').val();
		var AJAX_POST_URL = _base_url + "city";

		$.ajax({
			url: AJAX_POST_URL,
			type: "POST",
			data: {
				cmbArea: cmbArea
			},
			success: function(html)
			{	
				$('#cmbCity').html(html);
				// $('#cmbSubSubCategory').selectpicker('refresh');
			}
		});		

		return false;								
	});

	$("#searchTravel").click(function(){
		var key = $(txtKeyword).val();
		var area = $(cmbArea).val();
		var city = $(cmbCity).val();
		var AJAX_POST_URL = _base_url + "du-lich/travel-search";

		$.ajax({
			url: AJAX_POST_URL,
			type: "POST",
			data: {
				key: key,
				area: area,
				city: city
			},
			success: function(html)
			{	
				$('#dulich-list').html(html);
				$('#paging').html('');
			}
		});	

		return false;
	});

	$("#searchMember").click(function() {
		var key = $(txtKeyword).val();
		var area = $(cmbArea).val();
		var city = $(cmbCity).val();
		var AJAX_POST_URL = _base_url + "du-lich/travel-search";

		$.ajax({
			url: AJAX_POST_URL,
			type: "POST",
			data: {
				key: key,
				area: area,
				city: city
			},
			success: function(html)
			{	
				$('#dulich-list').html(html);
				$('#paging').html('');
			}
		});	

		return false;
	});
	
});